package classes {
	import mx.containers.Canvas;
	import mx.controls.Image;
	
	import spark.effects.Move;

	public class Bola {
		public static const MOVEMENT_TIME_PER_N_PIXELS:int = 100;
		public static const N_PIXELS:int = 50;
		private var xPos:Number, yPos:Number, radio:Number;
		private var move:Move;
		private var imagen:Image;
		
		public function Bola(_canvas:Canvas, _imgPath:String = "", _x:Number = 300, _y:Number = 300, _radio:Number = 10) {
			trace ("Constructor de bola");
			xPos = _x;
			yPos = _y;
			radio = _radio;
			
			imagen = new Image();
			imagen.load(_imgPath == ""? "img/bola.png" : _imgPath);
			move = new Move(imagen);
			var newCanvas:Canvas = new Canvas();
			newCanvas.addChild(imagen);
			_canvas.addChild(newCanvas);
			
			move.end();
			move.xTo = xPos;
			move.yTo = yPos;
			move.duration = 1;
			move.play();
		}
		
		public function moveTo(newX:Number, newY:Number): void {
			var time:Number = Math.round(Math.sqrt(Math.pow(xPos-newX, 2) + Math.pow(yPos-newY, 2)) / N_PIXELS) * MOVEMENT_TIME_PER_N_PIXELS;
			xPos = newX;
			yPos = newY;
			move.end();
			move.xTo = xPos;
			move.yTo = yPos;
			move.duration = time;
			move.play();
		}
		
		public function getX(): Number {
			return xPos;
		}
		
		public function getY(): Number {
			return yPos;
		}
	}
}